package com.sh.suhe.utildemos.utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.view.View;

import com.sh.suhe.utildemos.R;


/**
 * 对话框
 *
 * @author lvling
 * @time 2016/10/14 14:38
 */
public class DialogUtils extends Dialog {
  //  private static Context mContext;
  public final static int STYLE_ZEERO_BUTTON = -1;//两个按钮
    public final static int STYLE_ONE_BUTTON = 0; //一个按钮
    public final static int STYLE_TWO_BUTTON = 1;//两个按钮

    public DialogUtils(Context context) {
        super(context, R.style.noTitleDialog);
//        mContext = context;
    }

    /**
     * 创建对话框
     *
     * @param style      样式  STYLE_ONE_BUTTON = 0; //一个按钮 ；STYLE_TWO_BUTTON = 1;//两个按钮；
     * @param tips       提示信息
     * @param buttonname 按钮显示的内容
     * @param listener   监听
     * @return
     */
    public static AlertDialog setDialog(Context context, int style, String tips, String[] buttonname, OnClickListener listener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        switch (style) {
            case STYLE_ONE_BUTTON: {
                builder.setMessage(tips);
                builder.setPositiveButton(buttonname[0], listener);
            }
            break;
            case STYLE_TWO_BUTTON: {
                builder.setMessage(tips);
                builder.setPositiveButton(buttonname[0], listener);
                builder.setNegativeButton(buttonname[1], listener);
            }
            break;
        }
        return builder.create();
    }
    public static AlertDialog setDialog(int style, View view, String[] buttonname, OnClickListener listener,Context context) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        switch (style) {
            case STYLE_ZEERO_BUTTON: {
                builder.setView(view);
            }
            break;
            case STYLE_ONE_BUTTON: {
                builder.setView(view);
                builder.setPositiveButton(buttonname[0], listener);
            }
            break;
            case STYLE_TWO_BUTTON: {
                builder.setView(view);
                builder.setPositiveButton(buttonname[0], listener);
                builder.setNegativeButton(buttonname[1], listener);
            }
            break;
        }
        return builder.create();
    }
    public static AlertDialog setDialogTran(int style, View view, String[] buttonname, OnClickListener listener,Context context) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context );
        switch (style) {
            case STYLE_ZEERO_BUTTON: {
                builder.setView(view);
            }
            break;
            case STYLE_ONE_BUTTON: {
                builder.setView(view);
                builder.setPositiveButton(buttonname[0], listener);
            }
            break;
            case STYLE_TWO_BUTTON: {
                builder.setView(view);
                builder.setPositiveButton(buttonname[0], listener);
                builder.setNegativeButton(buttonname[1], listener);
            }
            break;
        }
        return builder.create();
    }

    public static Dialog createDialog(
            Context activity, int hobby, OnClickListener listener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setItems(hobby, listener);
        return builder.create();
    }
}
